﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpBolt.Editing;
using System.ComponentModel;

namespace SharpBolt.Graphics
{
    [TypeConverter(typeof(SBDColorConverter))]
    public struct DColor
    {
        public double a, r, g, b;

        public DColor(double a, double r, double g, double b)
        {
            this.a = a;
            this.r = r;
            this.g = g;
            this.b = b;
        }

        public Color ToColor(){
            Color color = new Color((int)(255 * a), (int)(255 * r), (int)(255 * g), (int)(255 * b));
            return color;
        }

        public static DColor operator +(DColor a, DColor b)
        {
            return new DColor(
                a.a + b.a,
                a.r + b.r,
                a.g + b.g,
                a.b + b.b);
        }

        public static DColor operator -(DColor a, DColor b)
        {
            return new DColor(
                a.a - b.a,
                a.r - b.r,
                a.g - b.g,
                a.b - b.b);
        }

        public static DColor operator *(DColor a, DColor b)
        {
            return new DColor(
               a.a * b.a,
               a.r * b.r,
               a.g * b.g,
               a.b * b.b);
        }

        public static DColor operator /(DColor a, DColor b)
        {
            return new DColor(
               a.a / b.a,
               a.r / b.r,
               a.g / b.g,
               a.b / b.b);
        }

        public static DColor operator *(DColor a, double number)
        {
            return new DColor(
               a.a * number,
               a.r * number,
               a.g * number,
               a.b * number);
        }

        public static DColor operator *(double number, DColor a)
        {
            return new DColor(
               a.a * number,
               a.r * number,
               a.g * number,
               a.b * number);
        }

        public static DColor operator /(DColor a, double b)
        {
            return new DColor(
               a.a / b,
               a.r / b,
               a.g / b,
               a.b / b);
        }

        public static bool operator ==(DColor a, DColor b)
        {
            return
                a.a == b.a &&
                a.r == b.r &&
                a.g == b.g &&
                a.b == b.b;
        }

        public static bool operator !=(DColor a, DColor b)
        {
            return !
                (a.a == b.a &&
                a.r == b.r &&
                a.g == b.g &&
                a.b == b.b);
        }

        public static DColor LinearTween(DColor a, DColor b, double part)
        {
            DColor result = b - a;
            result = result * part;
            result = a + result;
            return result;
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
